<template>
  <div class="menu_box">
    <van-image width="100%" :src="$filters.prefix(banner)" />
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div
          class="swiper-slide"
          v-for="(item, index) in navLinks"
          :key="index"
          @click="handNav(item.path)"
        >
          <div class="menu_item">
            <img
              class="ment_icon"
              :src="require('../assets/imgs/navIcon/' + item.imgUrl)"
              alt=""
            />
            <div class="title">
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination swiper-pagination-progress"></div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, reactive, ref, toRef, toRefs } from "vue";
import { useRouter } from "vue-router";
import storage from "@/utils/storage";
import { getDetails } from "@/utils/apis/home";
import { IMGURL } from "@/utils/config";
import Swiper from "swiper";
import "swiper/css/swiper.css";
import { navLinks } from "@/utils/local-data";
interface BgImgObj {
  banner: string;
}
export default defineComponent({
  name: "NavBar",
  props: {},
  setup() {
    const state = reactive({
      banner: "",
      navLinks: navLinks,
      details: {} as BgImgObj,
    });
    const router = useRouter();
    onMounted(async () => {
      const res = await getDetails();
      state.banner = res.data.banner;
      new Swiper(".swiper-container", {
        loop: false, // 循环模式选项
        // 如果需要分页器
        slidesPerView: 5,
        watchSlidesProgress: true,

        pagination: {
          el: ".swiper-pagination",
          type: "progressbar",
        },
      } as any);
    });
    const handNav = (path: string) => {
      router.push({
        path,
      });
    };
    return { ...toRefs(state), handNav };
  },
});
</script>
<style lang="scss">
.menu_box {
  .menu_banner {
    width: 100%;
  }
  .menu_item {
    margin-top: 25px;
    text-align: center;
    .title {
      font-size: 12px;
      color: #666;
    }
    .ment_icon {
      width: 46px;
      height: 46px;
      margin: 0 auto;
      margin-bottom: 4px;
    }
  }
}
.swiper-pagination-progress {
  position: relative !important;
  width: 40px !important;
  border-radius: 80px;
  overflow: hidden;
  margin: 0 auto;
  margin-top: 15px;
  background: rgba(0, 0, 0, 0.25);
}
.swiper-pagination-progressbar .swiper-pagination-progressbar-fill {
  background-color: $themeColor;
}
</style>
